/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.google.code.japidiff;

import org.objectweb.asm.Attribute;

public class JavaClass {

	private final int version;
	private final int access;
	private final String name;
	private final String signature;
	private final String superName;
	private final String[] interfaces;
	private Attribute[] attributes = new Attribute[0];
	private JavaAnnotation[] annotations = new JavaAnnotation[0];
	private JavaField[] fields = new JavaField[0];
	private JavaMethod[] methods = new JavaMethod[0];
    private boolean isInner;
    private JavaClass[] innerClasses = new JavaClass[0];

    public JavaClass(int version, int access, String name, String signature, String superName, String[] interfaces) {
		this.version = version;
		this.access = access;
		this.name = name;
		this.signature = signature;
		this.superName = superName;
		this.interfaces = interfaces;
	}

	public int getVersion() {
		return version;
	}

	public int getAccess() {
		return access;
	}

	public String getName() {
		return name;
	}

	public String getSignature() {
		return signature;
	}

	public String getSuperName() {
		return superName;
	}

	public String[] getInterfaces() {
		return interfaces;
	}

	public JavaAnnotation[] getAnnotations() {
		return annotations;
	}

	public JavaField[] getFields() {
		return fields;
	}

	public JavaMethod[] getMethods() {
		return methods;
	}

    public JavaClass[] getInnerClasses() {
        return innerClasses;
    }

    public boolean isInner() {
        return isInner;
    }

    public void addAttribute(Attribute attribute) {
		Attribute[] old = attributes;
		attributes = new Attribute[old.length + 1];
		for (int i = 0; i < old.length; i++) {
			attributes[i] = old[i];
		}
		attributes[old.length] = attribute;
	}
	
	public void addAnnotation(JavaAnnotation annotation) {
		JavaAnnotation[] old = annotations;
		annotations = new JavaAnnotation[old.length + 1];
		for (int i = 0; i < old.length; i++) {
			annotations[i] = old[i];
		}
		annotations[old.length] = annotation;
	}

	public void addField(JavaField field) {
        JavaField[] old = fields;
        fields = new JavaField[old.length + 1];
        for (int i = 0; i < old.length; i++) {
            fields[i] = old[i];
        }
        fields[old.length] = field;
	}

	public void addMethod(JavaMethod method) {
        JavaMethod[] old = methods;
        methods = new JavaMethod[old.length + 1];
        for (int i = 0; i < old.length; i++) {
            methods[i] = old[i];
        }
        methods[old.length] = method;
	}

    public void addInnerClass(JavaClass inner) {
        JavaClass[] old = innerClasses;
        innerClasses = new JavaClass[old.length + 1];
        for (int i = 0; i < old.length; i++) {
            innerClasses[i] = old[i];
        }
        innerClasses[old.length] = inner;
        inner.isInner = true;
    }
	
}
